#ifndef _QuadTree_h_
#define _QuadTree_h_
#include<windows.h>
#include"Object.h"
class CNode
{
public:
	int w;
	int h;
	int x;
	int y;
	int n;
	CNode *LeftTop;
	CNode *LeftBottom;
	CNode *RightTop;
	CNode *RightBottom;
	LIST list;
	RECT getRect();
	void AddObject(LIST &list,Object object);
	void RemoveObject(int);
	CNode(int _x,int _y,int _w,int _h)
	{
		x=_x;
		y=_y;
		w=_w;
		h=_h;
		LeftTop=RightTop=LeftBottom=RightBottom=NULL;
		list.pHead=NULL;
		list.pTail=NULL;
		list.n=0;
	}
	~CNode()
	{
		//if(list!=NULL) delete list;
		if(LeftTop!=NULL) delete LeftTop;
		if(RightTop!=NULL) delete RightTop;
		if(LeftBottom!=NULL) delete LeftBottom;
		if(RightBottom!=NULL) delete RightBottom;
	}

	
};
	void EmptyList(LIST &list);
class QuadTree
{
public:
	CNode *root;
	int nNode;
	QuadTree(int w,int h)
	{
		root= new CNode(0,0,w,h);
		nNode=1;
	}
	~QuadTree()
	{
		if(root!=NULL) delete root;
	}
	void getObjectFromFile(int level);
	void AddNode(CNode *parent,Object object);
	void getObject(CNode *parent,LIST &list,RECT screen);
	
	void getAllObject(CNode *parent,LIST &list);
	void Empty(CNode *root);
	int CollisionStaticObject(RECT objectRect,RECT marioRect);
	int CollisionList(CNode *parent,RECT marioRect);
};
#endif
